<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-select v-model="query.groupid" clearable placeholder="主机组" class="filter-item" style="width: 240px" @change="_getHosts">
      <el-option v-for="item in groups" :key="item.groupid" :label="item.name" :value="item.groupid" />
    </el-select>
    <el-select v-model="query.hostid" clearable placeholder="主机" class="filter-item" style="width: 240px" @change="_getGraphs">
      <el-option v-for="item in hosts" :key="item.hostid" :label="item.hostname" :value="item.hostid" />
    </el-select>
    <el-select v-model="query.graphid" clearable placeholder="图表" class="filter-item" style="width: 240px" @change="_getImage">
      <el-option v-for="item in graphs" :key="item.graphid" :label="item.graphname" :value="item.graphid" />
    </el-select>
  </div>
</template>

<script>
import { getGroups, getHosts, getGraphs } from '@/api/tZabbix'
export default {
  props: {
    query: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      queryTypeOptions: [
        { key: 'name', display_name: '设备类型' },
        { key: 'eqptsystemid', display_name: '所属系统id' }
      ],
      groups: [],
      hosts: [],
      graphs: []
    }
  },
  mounted() {
    this._getGroups()
  },
  methods: {
    _getImage(imageId) {
      this.$parent.getImage(imageId)
    },
    _getGroups() {
      getGroups(true).then(res => {
        this.groups = res
      })
    },
    _getHosts(groupId) {
      getHosts(groupId).then(res => {
        this.hosts = res
      })
    },
    _getGraphs(hostsId) {
      getGraphs(hostsId).then(res => {
        this.graphs = res
      })
    }
  }
}
</script>
